﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_9
{
    public partial class Form1 : Form
    {
        private bool isEncrypted = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private string Rot13(string input)
        {
            char[] result = new char[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                char c = input[i];
                if (Char.IsLetter(c))
                {
                    int baseOffset = Char.IsUpper(c) ? 'A' : 'a';
                    result[i] = (char)(((c - baseOffset + 13) % 26) + baseOffset);
                }
                else
                {
                    result[i] = c;
                }
            }
            return new string(result);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string text = textBox1.Text;
            string transformedText = Rot13(text);
            textBox1.Text = transformedText;

            if (isEncrypted)
            {
                button1.Text = "加密";
                isEncrypted = false;
            }
            else
            {
                button1.Text = "解密";
                isEncrypted = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            button1.Text = "加密";
            isEncrypted = false;
        }
    }
}

